package com.lagou.homework.stage01.module3;

import java.util.*;

public class Task5 {
    static List<String> cards = new ArrayList<>();

    public static void main(String[] args) {
        Map<Integer, String> mapA = new TreeMap<>();
        Map<Integer, String> mapB = new TreeMap<>();
        Map<Integer, String> mapC = new TreeMap<>();

        Task5.setCards();
        Collections.shuffle(cards);

        for (int i = 0; i < cards.size() - 3; i++) {
            for (int j = 0; j < 4; j++) {
                if (null == mapA.put(Task5.getKey(cards.get(i)) + j, cards.get(i))) {
                    break;
                }
            }
            i++;
            for (int j = 0; j < 4; j++) {
                if (null == mapB.put(Task5.getKey(cards.get(i)) + j, cards.get(i))) {
                    break;
                }
            }
            i++;
            for (int j = 0; j < 4; j++) {
                if (null == mapC.put(Task5.getKey(cards.get(i)) + j, cards.get(i))) {
                    break;
                }
            }
        }

        System.out.print("玩家A的牌：");
        for (String value : mapA.values()) {
            System.out.print(value + "\t");
        }
        System.out.println();

        System.out.print("玩家B的牌：");
        for (String value : mapB.values()) {
            System.out.print(value + "\t");
        }
        System.out.println();

        System.out.print("玩家C的牌：");
        for (String value : mapC.values()) {
            System.out.print(value + "\t");
        }
    }

    static int getKey(String value) {
        switch (value) {
            case "bigKing":
                return 1;
            case "smallKing":
                return 2;
            case "2":
                return 3;
            case "A":
                return 7;
            case "K":
                return 11;
            case "Q":
                return 15;
            case "J":
                return 19;
            case "10":
                return 23;
            case "9":
                return 27;
            case "8":
                return 31;
            case "7":
                return 35;
            case "6":
                return 39;
            case "5":
                return 43;
            case "4":
                return 47;
            case "3":
                return 51;
        }
        return 0;
    }

    static void setCards() {
        cards.add("bigKing");
        cards.add("smallKing");

        for (int i = 0; i < 4; i++) {
            for (int j = 1; j <= 13; j++) {
                if (j == 1) {
                    cards.add("A");
                } else if (j == 11) {
                    cards.add("J");
                } else if (j == 12) {
                    cards.add("Q");
                } else if (j == 13) {
                    cards.add("K");
                } else {
                    cards.add(String.valueOf(j));
                }
            }
        }
    }
}
